<!-- 分页使用 
  <common-pagination
        :total="tableData.length"
        :current-page="currentPage"
        :page-size="pageSize"
        @update:currentPage="currentPage = $event"
        @update:pageSize="pageSize = $event"
      />
      
      import CommonPagination from '@/components/common/CommonPagination.vue';
      components: {CommonPagination},
      data() {
        return {
          currentPage: 1,
          pageSize: 10,
          tableData: [],
        };
      },
       computed: {
    paginatedData () {//获取当前页数据//<el-table:data="paginatedData">
      const start = (this.currentPage - 1) * this.pageSize;//计算当前页索引
      const end = start + this.pageSize;//计算当前页结束的索引位置
      return this.tableData.slice(start, end);//根据计算的起始和结束索引，从 tableData 中截取当前页的数据并返回。
    }
  }
      -->

<template>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    total: {
      type: Number,
      required: true
    },
    currentPage: {
      type: Number,
      required: true
    },
    pageSize: {
      type: Number,
      required: true
    }
  },
  methods: {
    handleSizeChange (newPageSize) {
      this.$emit('update:pageSize', newPageSize);//触发 update:pageSize 事件，并传递新的每页显示数量
      this.$emit('update:currentPage', 1); //更改size后，重置当前页码为1，避免超出范围，出现无效页码
    },
    handleCurrentChange (newPage) {
      this.$emit('update:currentPage', newPage);
    }
  }
};
</script>

<style scoped>
.block {
  margin-top: 10px;
}
.demonstration {
  display: block;
  color: #000000;
  font-size: 14px;
  margin-bottom: 20px;
}
::v-deep .el-input__inner {
  color: #000000; /* 修改跳转输入框中的字体颜色 */
}
::v-deep .btn-prev:hover,
::v-deep .btn-next:hover,
::v-deep .number:hover {
  color: #716f6f; /* 修改按钮悬停时的字体颜色 */
  background-color: #f5f7fa; /* 修改按钮悬停时的背景颜色 */
}

::v-deep .el-pagination__total {
  color: #000000; /* 修改总记录数文本的字体颜色 */
}
::v-deep .el-pagination__jump {
  color: #000000; /* 修改跳转输入框的字体颜色 */
}
::v-deep .el-pager li.active {
  color: #716f6f; /* 修改当前页码的字体颜色 */
  /*background-color: #777879;  修改当前页码的背景颜色 */
}
::v-deep .el-pager li {
  background-color: transparent; /* 去掉页码的背景颜色 */
}
::v-deep .btn-prev {
  background-color: transparent; /* 去掉背景颜色 */
  border: none; /* 去掉边框 */
}
::v-deep .btn-next {
  background-color: transparent; /* 去掉背景颜色 */
  border: none; /* 去掉边框 */
}
</style>



